﻿@using TbShop.Web.Helpers;
@using TbShop;
@{
    ViewBag.Title = "角色列表";
    ViewBag.ModuleId = "Role";
    var isAdd = AuthorizationHelper.IsAuthorised(Constants.AuthorityIdentity.AddRole);
    var isEdit = AuthorizationHelper.IsAuthorised(Constants.AuthorityIdentity.EditRole);
    var isDel = AuthorizationHelper.IsAuthorised(Constants.AuthorityIdentity.DeleteRole);
    var isRole =AuthorizationHelper.IsAuthorised(Constants.AuthorityIdentity.RoleAuthority);
}

<div class="panel panel-default">
    <div class="panel-heading">
        <strong>角色列表</strong>
        <div class="pull-right">
            @if (isAdd)
            {
                <a href="@(Url.Action("Edit","Role"))"><span class='glyphicon glyphicon-plus' aria-hidden='true'></span> 添加新角色</a>
            }
        </div>
    </div>
    <div class="panel-body">
        <table id="role_table"></table>
    </div>
</div>

@using (Html.BeginForm("Delete", "Role", FormMethod.Post, new { id = "DeleteForm" }))
{
    @Html.AntiForgeryToken()
    <input type="hidden" name="id" value="0" />
    <input type="hidden" name="versionNumber" value="0" />
}

@section scripts{
    @Styles.Render("~/bundles/editable-table-css")
    @Scripts.Render("~/bundles/editable-table")
    <script type="text/javascript">
        function deleted(id, vnum) {
            $("#DeleteForm input[name='id']").val(id);
            $("#DeleteForm input[name='versionNumber']").val(vnum);
            dialog({
                title: "确认删除",
                content: "是否确认删除该角色？",
                width: "200",
                okValue: "确认",
                ok: function () {
                    $("#DeleteForm").submit();
                },
                cancelValue: "取消",
                cancel: function () {
                }
            }).showModal();
        }
        $(function () {
            $('#role_table').bootstrapTable({
                columns: [{
                    title: '名称',
                    field: 'Name'
                }, {
                    title: '添加时间',
                    field: 'CreatedDate',
                    formatter: function (value) {
                        return (new Date(value)).format("yyyy-MM-dd hh:mm");
                    }
                }, {
                    title: '操作',
                    field: 'Id',
                    formatter: function (value, row, index) {
                        return ('@(isEdit ? "true" : "false")' == 'true' ? '<a href="@(Url.Action("Edit"))?id=' + value + '"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span>修改</a>&nbsp;&nbsp;' : '') +
                            ('@(isRole ? "true" : "false")' == 'true' ? '<a href="@(Url.Action("Setting", "Authority"))?roleid=' + value + '"><span class="glyphicon glyphicon-briefcase" aria-hidden="true"></span>权限</a>&nbsp;&nbsp;' : '')+
                            (!row.IsSystem ? ('@(isDel ? "true" : "false")' == 'true' ? '<a href="javascript:void(0)" onclick="deleted(\'' + value + '\',\'' + row.VersionNumber + '\')"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span>删除</a>&nbsp;&nbsp;' : '') : '') ;
                    }
                }
                ],
                idField: 'Id',
                pagination: true,
                sidePagination: 'server',
                url: '@Url.Action("GetRoleList")',
                queryParamsType: '',
                queryParams: function (params) {
                    return params;
                },
                locale: 'zh-CN'
            });
        })
    </script>
}